package com.ok.activity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ok.activity.domain.dto.OkActivityDto;
import com.ok.activity.domain.po.OkActivity;
import com.ok.activity.mapper.OkActivityMapper;
import com.ok.activity.service.IOkActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.reflections.util.Utils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 活动 服务实现类
 * </p>
 *
 * @author lhw
 * @since 2024-04-29
 */
@Service
public class OkActivityServiceImpl extends ServiceImpl<OkActivityMapper, OkActivity> implements IOkActivityService {

    @Override
    public void add(OkActivityDto okActivityDto) {
        OkActivity okActivity = new OkActivity();
        //对象拷贝
        BeanUtils.copyProperties(okActivityDto,okActivity);
        this.save(okActivity);
    }

    @Override
    public Page<OkActivity> pageWith(Integer pageNo, Integer pageSize, String name) {
        Page<OkActivity> page = new Page<>(pageNo,pageSize);
        //模糊姓名查询
        LambdaQueryWrapper<OkActivity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(!Utils.isEmpty(name),OkActivity::getName,name);

        return this.page(page,queryWrapper);
    }
}
